package com.faner.controller.spider


import com.faner.spider.News
import com.fun.frame.SourceCode
import com.fun.utils.WriteHtml
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.ResponseBody

import javax.servlet.http.HttpServletRequest

@RequestMapping("/spider")
@Controller
class NewsController extends SourceCode {
    private static org.slf4j.Logger logger = LoggerFactory.getLogger(NewsController.class);
    @Autowired
    private HttpServletRequest request;

    @RequestMapping("/it")
    @ResponseBody
    String getNews() {
        def news = News.getItNews()
        def sina = News.getSina()
        def wy = News.wy()
        news.putAll(sina)
        news.putAll(wy)
        List<List<Object>> list = new ArrayList<>()
        List<Object> title = Arrays.asList("新闻标题", "新闻链接")
        list.add(title)
        def keys = news.keySet()
        List<String> lists = new ArrayList<>(keys)
        lists.each { key ->
            def s = new String(key.toString().getBytes(), UTF_8)
            def ss = new String(news.get(key).toString().getBytes(), UTF_8)
            ss = "<a href=\"" + ss + "\">传送门</a>"
            list.add(Arrays.asList(s, ss))
        }
        return WriteHtml.createWebReport(list, "新闻接口").toString()
    }
}
